package com.xiezc;

import com.xiaoleilu.hutool.cache.impl.TimedCache;
import com.xiezc.util.TicketInterceptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.annotation.Resource;

@SpringBootApplication
public class TBPanServerApplication extends SpringBootServletInitializer {

    /**
     * 缓存工具类
     *
     * @return
     */
    @Bean
    public TimedCache createTimedCache() {
        TimedCache timedCache = new TimedCache(2 * 60 * 60 * 1000L);
        return timedCache;
    }

    public static void main(String[] args) {
        SpringApplication.run(TBPanServerApplication.class);
    }

    @Configuration
    class WebConfig extends WebMvcConfigurerAdapter {

        @Resource
        private TicketInterceptor ticketInterceptor;

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(ticketInterceptor)
                    .addPathPatterns("/fileInfo/**")
                    .addPathPatterns("/upload/**")
                    .addPathPatterns("/download/**");
        }
    }
}